<template>
  <!-- 这个版本是没有更换暗黑风格系列ui的版本 -->
  <div class="my_index">
    <div
      v-if="!userInfo.enterpriseName"
      :class="userInfo.enterpriseName ? '' : 'pop'"
    >
      <div class="spinner">
        <div class="bounce1"></div>
        <div class="bounce2"></div>
        <div class="bounce3"></div>
      </div>
    </div>
    <div class="bacggroud_wraper"></div>
    <header class="top">
      <header class="vip">
        <section class="con">
          <div class="header">
            <div class="avatar">
              <img
                :src="userInfo.blogProfilePhoto"
                alt=""
                v-if="!!userInfo.blogProfilePhoto"
              />
              <img src="~static/common/header.png" alt="" v-else />
            </div>
          </div>
          <div class="right">
            <div class="station">
              {{ userInfo.enterpriseName }}
            </div>
            <div class="grade">{{ userInfo.gradeName }}</div>
            <div class="amount_container">
              <div class="text">
                卡余额：<span class="amount">￥{{ userInfo.balance }}</span>
              </div>
              <router-link
                :to="'/' + enterpriseId + '/charge/amount'"
                class="go_remit"
              >
                充值
              </router-link>
            </div>
          </div>
          <div class="scan" @click="scanShow = true">
            <span class="tip"></span>
          </div>
        </section>
        <div class="vip_bottom">
          <div class="bot_left">
            <router-link
              :to="'/' + enterpriseId + '/point'"
              class="integral_container"
            >
              <div class="integral">
                积分：<span class="value">{{ userInfo.integral }}</span>
              </div>
            </router-link>
            <router-link
              :to="'/' + enterpriseId + '/coupon'"
              class="integral_container"
            >
              <div class="integral">
                优惠劵：<span class="value">{{ userInfo.couponCount }}</span>
              </div>
            </router-link>
          </div>
          <div class="no">NO.{{ userInfo.memberCode }}</div>
        </div>
      </header>
    </header>
    <footer class="bottom">
      <div class="title">VIP 特权</div>
      <div class="cont">
        <nuxt-link
          class="item"
          :to="'/' + enterpriseId + '/record/consume'"
          tag="div"
        >
          <div class="icon charge"></div>
          <div class="text">我的订单</div>
        </nuxt-link>
        <nuxt-link
          class="item"
          :to="'/' + enterpriseId + '/record/charge'"
          tag="div"
        >
          <div class="icon consume"></div>
          <div class="text">充值订单</div>
        </nuxt-link>
        <nuxt-link
          class="item"
          :to="'/' + enterpriseId + '/setting/info'"
          tag="div"
        >
          <div class="icon car"></div>
          <div class="text">我的爱车</div>
        </nuxt-link>
        <nuxt-link class="item" :to="'/' + enterpriseId + '/plus'" tag="div">
          <div class="icon svip"></div>
          <div class="text">超级会员</div>
        </nuxt-link>
        <!-- <div
          class="item"
          tag="div"
          @click="gotoSomePage('/charge/?enterpriseId=' + enterpriseId)"
        > -->
        <router-link
          :to="'/charge/?enterpriseId=' + enterpriseId"
          tag="div"
          class="item"
        >
          <div class="icon vip"></div>
          <div class="text">会员卡</div>
        </router-link>
        <!-- </div> -->

        <nuxt-link
          class="item"
          tag="div"
          :to="'/' + enterpriseId + '/recommend/recommend'"
        >
          <div class="icon recommend"></div>
          <div class="text">推荐有奖</div>
        </nuxt-link>
        <nuxt-link
          class="item"
          :to="'/' + enterpriseId + '/setting/pay'"
          tag="div"
        >
          <div class="icon pay"></div>
          <div class="text">支付设置</div>
        </nuxt-link>
        <nuxt-link class="item" :to="'/' + enterpriseId + '/fuel'" tag="div">
          <div class="icon fuel"></div>
          <div class="text">油站导航</div>
        </nuxt-link>

        <nuxt-link
          class="item"
          :to="'/' + enterpriseId + '/today-price'"
          tag="div"
        >
          <div class="icon remit"></div>
          <div class="text">今日油价</div>
        </nuxt-link>

        <nuxt-link class="item" :to="'/' + enterpriseId + '/car'" tag="div">
          <div class="icon teamcard"></div>
          <div class="text">我的车队</div>
        </nuxt-link>
      </div>
      <div class="goApplet" @click="goFuelOrRemit()">
        <div class="item">
          <div class="icon setting"></div>
          <div class="text">快捷加油</div>
        </div>
      </div>
    </footer>

    <van-overlay :show="scanShow" @click.stop="scanShow = false">
      <div class="scan_wrapper">
        <div class="block">
          <div class="title">会员码</div>
          <qr
            :text="userInfo.memberCode"
            @downloadImg="downloadImg"
            name="二维码"
            class="qr"
          >
            <div style="text-align: center">用于识别会员身份，参与站内活动</div>
          </qr>
        </div>
      </div>
    </van-overlay>
  </div>
</template>

<script>
import { mapState, mapGetters, mapActions, mapMutations } from "vuex";
import wx from "weixin-js-sdk";
import Qr from "@/components/QrCode";
import Vue from "vue";
import { Overlay } from "vant";
Vue.use(Overlay);

export default {
  head() {
    return {
      title: "我的"
    };
  },
  data() {
    return {
      showGoApplet: true,
      infoData: {},
      scanShow: false
    };
  },
  components: {
    Qr: Qr
  },
  computed: {
    ...mapGetters({
      userInfo: "authen/userInfo"
    })
    // ...mapState({
    //   // pointInfo: (state) => state.point.pointInfo,
    // }),
  },
  created() {
    if (this.phone) {
      // this.getInfo();
      this.goto();
      this.getUserInfo();
    }
  },
  methods: {
    ...mapActions({
      // getPointInfo: "point/getPointInfo",
    }),
    ...mapActions({
      getSdkConfig: "authen/getSdkConfig"
    }),
    ...mapMutations({
      setUserInfo: "authen/setUserInfo"
    }),
    goFuelOrRemit() {
      // 获取油站信息列表
      this.$axios
        .$get("/appletSelectStationList", {
          params: { enterpriseId: this.enterpriseId }
        })
        .then(res => {
          if (res.retCode != 0) {
            throw new Error("获取油站失败");
          }
          const { stationId, stationName } = res.data.stationList[0] || {};
          if (res.data.stationList.length === 1) {
            this.$router.push({
              path: `/${this.enterpriseId}/fuel/remit/?stationId=${stationId}&stationName=${stationName}`
            });
          } else {
            this.$router.push({
              path: `/${this.enterpriseId}/fuel`
            });
          }
        })
        .catch(err => {
          alert(err);
        });
    },
    async getUserInfo() {
      try {
        const infoData = await this.$axios.$get("/selectMemberInfo", {
          params: {
            enterpriseId: this.enterpriseId,
            mobilePhone: this.phone
          }
        });

        if (infoData.retCode !== 0) {
          throw new Error(infoData.message);
        }
        this.setUserInfo(infoData.data);
        console.log(infoData.data);
      } catch (error) {
        alert(error);
      }
    },
    goto() {
      const that = this;
      this.getSdkConfig({
        jsApiList: ["wx-open-launch-weapp"],
        openTagList: ["wx-open-launch-weapp"]
      }).then(res => {
        wx.config(res);
        wx.error(function(err) {
          console.log(err);
          that.showGoApplet = false;
        });
      });
    },
    gotoSomePage(url) {
      // localStorage.clear();
      // sessionStorage.clear();
      window.open(url);
    }
  }
};
</script>

<style lang="scss" scoped>
.my_index {
  width: 100vw;
  box-sizing: border-box;

  .pop {
    position: absolute;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    background-color: #ccc;
    opacity: 0.3;
    z-index: 999;

    .spinner {
      margin: 40vh auto 0;
      width: 70px;
      text-align: center;
    }

    .spinner > div {
      width: 18px;
      height: 18px;
      background-color: black;

      border-radius: 100%;
      display: inline-block;
      -webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
      animation: sk-bouncedelay 1.4s infinite ease-in-out both;
    }

    .spinner .bounce1 {
      -webkit-animation-delay: -0.32s;
      animation-delay: -0.32s;
    }

    .spinner .bounce2 {
      -webkit-animation-delay: -0.16s;
      animation-delay: -0.16s;
    }

    @-webkit-keyframes sk-bouncedelay {
      0%,
      80%,
      100% {
        -webkit-transform: scale(0);
      }

      40% {
        -webkit-transform: scale(1);
      }
    }

    @keyframes sk-bouncedelay {
      0%,
      80%,
      100% {
        -webkit-transform: scale(0);
        transform: scale(0);
      }

      40% {
        -webkit-transform: scale(1);
        transform: scale(1);
      }
    }
  }

  .bacggroud_wraper {
    position: absolute;
    width: 100%;
    top: 0;
    height: 50vh;
    background-color: #000;
    z-index: -1;
  }

  .top {
    position: absolute;
    z-index: 1;
    top: 0;
    padding: 0 0.35rem;

    .vip {
      width: 100%;
      padding: 0.2rem 0.32rem 0.1rem;
      box-sizing: border-box;
      background: url("../../static/fuel/加油站信息.png") no-repeat 0 0;
      background-size: 100% 100%;
      width: 6.8rem;
      height: 2.8rem;
      border-radius: 0.3rem;

      > .con {
        display: flex;
        position: relative;

        .header {
          margin-right: 0.3rem;

          .avatar {
            width: 1.04rem;
            height: 1.04rem;
            border-radius: 50%;

            > img {
              width: 100%;
              height: 100%;
            }
          }
        }

        .right {
          display: flex;
          flex-direction: column;
          justify-content: space-between;

          .station {
            margin-top: 0.1rem;
            font-weight: 500;
            font-size: 0.36rem;
            color: #333;

            .icon {
              // background: url("../../static/vip/vipicon.png") no-repeat 0 0;
              background-size: 100% 100%;
              display: inline-block;
              width: 0.25rem;
              height: 0.25rem;
            }
          }

          .grade {
            height: 0.29rem;
            margin: 0.12rem 0;
            font-size: 0.24rem;
            color: #d9a85a;
          }

          .amount_container {
            display: flex;
            align-items: center;

            .text {
              color: #d8a458;
              font-size: 0.26rem;

              .amount {
                font-size: 0.36rem;
                font-weight: 500;
              }
            }

            .go_remit {
              margin-left: 0.14rem;
              text-align: center;
              font-size: 0.2rem;
              width: 0.64rem;
              border-radius: 0.2rem;
              background-color: #fff;
              color: #d9a85a;
              height: 0.36rem;
              line-height: 0.36rem;
            }
          }
        }

        .scan {
          width: 0.42rem;
          height: 0.42rem;
          position: absolute;
          right: 0.06rem;
          top: 0.1rem;
          background: url("../../static/vip/scan3.png") no-repeat 0 0;
          background-size: 100% 100%;

          .tip {
            background: url("../../static/fuel/到店扫码.png") no-repeat 0 0;
            background-size: 100% 100%;
            display: inline-block;
            width: 1.1rem;
            height: 0.4rem;
            right: -0.32rem;
            position: absolute;
            bottom: -0.45rem;
          }
        }
      }

      .vip_bottom {
        width: 100%;
        margin-top: 0.43rem;
        display: flex;
        justify-content: space-between;
        align-items: center;

        .bot_left {
          display: flex;
          justify-content: space-between;
          min-width: 3.2rem;

          .integral_container {
            margin-left: 0.1rem;
            display: flex;

            .integral {
              padding: 0.04rem 0.18rem;
              border-radius: 0.32rem;
              background-color: #fff;
              color: #d9a85a;
              font-size: 0.24rem;

              .value {
                font-size: 0.3rem;
                font-weight: 600;
              }
            }
          }
        }

        .no {
          font-size: 0.25rem;
          color: #fadc93;
        }
      }
    }
  }

  .bottom {
    width: 100%;
    margin-top: 2.1rem;
    min-height: calc(100vh - 2.3rem);
    box-sizing: border-box;
    background-color: #fff;
    padding: 1.2rem 0.35rem;
    border-radius: 0.3rem 0.3rem 0 0;

    // margin-top: 0.4rem;
    > .title {
      color: #404040;
      font-weight: bolder;
      font-size: 0.28rem;
    }

    > .cont {
      margin: 0 auto;
      margin-top: 0.4rem;
      display: flex;
      flex-wrap: wrap;
      align-content: space-between;

      .item {
        width: 1.2rem;
        display: flex;
        flex-direction: column;
        align-items: center;
        margin-right: 0.65rem;
        margin-bottom: 0.64rem;

        .icon {
          width: 0.8rem;
          height: 0.8rem;
          background-color: rgba(240, 210, 153, 100);
          background-size: 100% 100%;
          margin-bottom: 0.36rem;
        }

        .text {
          height: 0.32rem;
          color: rgba(87, 87, 87, 100);
          font-size: 0.26rem;
          text-align: center;
        }

        &:nth-child(4n) {
          margin-right: 0;
        }
      }

      .item {
        .vip {
          background: url("../../static/fuel/vip.png") no-repeat 0 0;
          background-size: 100% 100%;
        }
      }

      .item {
        .charge {
          background: url("../../static/fuel/一键加油.png") no-repeat 0 0;
          background-size: 100% 100%;
        }
      }

      .item {
        .car {
          background: url("../../static/fuel/car.png") no-repeat 0 0;
          background-size: 100% 100%;
        }
      }

      .item {
        .recommend {
          background: url("../../static/fuel/推荐有奖.png") no-repeat 0 0;
          background-size: 100% 100%;
        }
      }

      .item {
        .svip {
          background: url("../../static/fuel/svip.png") no-repeat 0 0;
          background-size: 100% 100%;
        }
      }

      .item {
        .consume {
          background: url("../../static/fuel/图层\ 12.png") no-repeat 0 0;
          background-size: 100% 100%;
        }
      }

      .item {
        .pay {
          background: url("../../static/fuel/设置.png") no-repeat 0 0;
          background-size: 100% 100%;
        }
      }

      .item {
        .fuel {
          background: url("../../static/fuel/daohang.png") no-repeat 0 0;
          background-size: 100% 100%;
        }
      }

      .item {
        .remit {
          background: url("../../static/fuel/remit.png") no-repeat 0 0;
          background-size: 100% 100%;
        }
      }

      .item {
        .teamcard {
          background: url("../../static/fuel/car2.png") no-repeat 0 0;
          background-size: 100% 100%;
        }
      }
    }
  }

  .goApplet {
    margin: 0 auto;
    margin-top: 1rem;
    width: 6rem;
    height: 0.8rem;
    background: linear-gradient(-67deg, #fdb816, #fb8b0a);
    border-radius: 0.4rem;
    text-align: center;
    font-size: 0.4rem;
    color: #ffffff;
    line-height: 0.8rem;
  }

  .scan_wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;

    .block {
      width: 6rem;
      padding: 0.5rem 1rem 0.7rem 1rem;
      box-sizing: border-box;
      border-radius: 0.3rem;
      background-color: #fff;

      .title {
        font-size: 0.3rem;
        line-height: 0.3rem;
        text-align: center;
        margin-bottom: 0.3rem;
        font-weight: bold;
      }

      .qr {
        width: 100%;
      }
    }
  }
}
</style>
